<template>
  <div class="container">
    <data-view
      propViewKey="base_inspection_equipment"
      propViewForm="base/insp/detail.vue"
      :propFlowKey="propFlowKey"
      @extra-button-click="extraButtonClick"
      :propIsTdesign="true"
    />
  </div>
</template>

<script>

export default {
  name: 'inspectionequipment',
  data() {
    return {

    }
  },
  components: {

  },
  methods: {
    extraButtonClick({button, data, index}) {
      const { key: buttonKey } = button
      if (buttonKey === 'printsn') {
        if (data && data.length > 0) {
          this.print(data)
        }
      }
    },
    print(data) {
      let rows = []
      data.forEach(row => {
        if (row.flagTesting) {
          rows.push({
            matrName: row.name,
            hrpCode: row.code,
            sn: row.sn
          })
        }
      })

      let printerLabelServerid = this.utils.loadUserState(this, 'printer_label_serverid')
      let printerLabelServerTypeKey = this.utils.loadUserState(this, 'printer_label_server_type_key')

      if (!printerLabelServerid) {
        this.utilMessage.warning('请先到工作台设置标签打印服务器')
        return
      }

      if (printerLabelServerTypeKey == 'rfid') { //RFID打印机
        this.utilVue.loadShow(true)
        let params = {
          snArr: [],
          printerId: printerLabelServerid

        }
        rows.forEach(obj => { params.snArr.push(obj.sn) })
        this.$ajax.post('/tool/printRFID', params, {timeout: 1000 * 60 * 10}).then(resp => {
          if (resp.code == 0) {
            this.utilMessage.success(resp.msg)
          }
          this.utilVue.loadHide()
          this.$refs.dataview.ocRefresh()
        })
      } else if (printerLabelServerTypeKey == 'label') { //普通标签打印机
        let param = {
          rows,
          hideColumns: ['lot', 'mfgName', 'expDate', 'matrSpec', 'packageUnit']
        }
        global.utilPrint.openLabel(param)
      }
    }
  },
  props: ['propFlowKey'],
}
</script>
